package com.single;

/**
 * @author cyf
 * @description 单例模式
 * @create 2018-09-20 17:54
 **/
public class SingleTon {


    /**
     *  懒汉模式 ：线程不安全，多线程情况下，可能会被实例化多次。
     */

    private static SingleTon instance;

    private SingleTon() {
    }

    public static SingleTon getInstance() {
        if(null == instance){
            instance = new SingleTon();
        }
        return instance;
    }

    public static void main(String[] args) {
        SingleTon instance = SingleTon.getInstance();
        SingleTon instance1 = SingleTon.getInstance();
        System.out.println(instance == instance1);
    }

}
